package com.rowger.player.adapter

import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import com.itheima.player.model.bean.HomeItemBean
import com.rowger.player.widget.HomeItemView

/**
 * Created by Administrator on 2018/5/15.
 */
class HomeAdapter: RecyclerView.Adapter<HomeAdapter.HomeHolder>() {
    private var list=ArrayList<HomeItemBean>()
     /*
     * 更新数据
     * */
    fun updateList(list: List<HomeItemBean>){
        this.list.clear()
         this.list.addAll(list)
         notifyDataSetChanged()
    }

    override fun onBindViewHolder(holder: HomeHolder?, position: Int) {
       //条目数据
        val data = list.get(position)
        //条目view
        val itemView=holder?.itemView as HomeItemView
        //条目刷新
        itemView.setData(data)
    }
    override fun getItemCount(): Int {
        return list.size
    }

    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): HomeHolder {
       return HomeHolder(HomeItemView(parent?.context))
        //return  HomeHolder(HomeItemView(parent?.context))
    }



    class HomeHolder(itemView:View):RecyclerView.ViewHolder(itemView){

    }
}